package Demo03;

import java.util.Arrays;

/**
 * @ClassName Test
 * @Description TODO
 * @Author 李明忠
 * @Date 2025/5/5 15:11
 * @Version 1.0
 */
class Student implements Comparable<Student> {
    int age;
    String name;

    public Student(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }


    /**
     * @param o the object to be compared.
     * @return
     */
    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }
}
public class Test {
    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student(10,"lihuw");
        students[1] = new Student(10,"lihuw");
        students[2] = new Student(10,"lihuw");
        AgeComparator ageComparator = new AgeComparator();

        Arrays.sort(students,ageComparator);

        ageComparator.compare(students[0],students[1]);
        System.out.println(new Student(10, "lisi").compareTo(new Student(90, "zd")));
    }
}
